<template>
    <swiper :options="swiperOption" ref="mySwiper">
      <template v-for="(item,index) in showList">
        <swiper-slide :key="index">
          <div class="slider-main" :style="{height:height+'px'}">
            <div class="backgroud">
            <img class="backgroud-img" v-lazy="domin+item.s_haibao" :style="{width:width+'px'}">
            </div>
            <div class="cover"><img v-lazy="domin+item.s_haibao"></div>
            <h1>{{item.s_title}}</h1>
            <h1>{{item.s_username}}</h1>
            <div>
              {{item.s_show}}
            </div>
            <h2>
            展览时间：
              <p>{{item.s_starttime | formatDate('yyyy/MM/dd')}}-{{item.s_endtime | formatDate('yyyy/MM/dd')}}</p>
            </h2>
            <div class="skip"><mt-button plain @click="skipDetail(item.id)">去看展</mt-button></div>
          </div>
        </swiper-slide>
      </template>
      <div class="swiper-pagination"  slot="pagination"></div>
      <div class="swiper-scrollbar"   slot="scrollbar"></div>
    </swiper>
</template>
<script>
export default {
  data () {
    return {
      height: '',
      width: '',
      swiperOption: {
        // NotNextTick is a component's own property, and if notNextTick is set to true, the component will not instantiate the swiper through NextTick, which means you can get the swiper object the first time (if you need to use the get swiper object to do what Things, then this property must be true)
        // notNextTick是一个组件自有属性，如果notNextTick设置为true，组件则不会通过NextTick来实例化swiper，也就意味着你可以在第一时间获取到swiper对象，假如你需要刚加载遍使用获取swiper对象来做什么事，那么这个属性一定要是true
        notNextTick: true,
        // effect:"coverflow",
        grabCursor: true,
        setWrapperSize: true,
        pagination: '.swiper-pagination',
        paginationType: 'fraction',
        paginationFractionRender: (swiper, currentClassName, totalClassName) => {
          return `<span class="${currentClassName}"></span> - <span class="${totalClassName}"></span>`
        },
        scrollbar: '.swiper-scrollbar',
        mousewheelControl: true,
        observeParents: true
      },
      showList: []
    }
  },
  computed: {
    swiper () {
      return this.$refs.mySwiper.swiper
    }
  },
  mounted () {
    let h = window.innerHeight
    let w = window.innerWidth
    this.height = h
    this.width = w
    window.addEventListener('resize', () => {
      let h = window.innerHeight
      let w = window.innerWidth
      this.height = h
      this.width = w
    })
    this.getShow()
  },
  methods: {
    getShow () {
      this.$http.show().then(res => {
        this.showList = res.data
      }).catch(err => {
        console.error(err)
        this.$toast({
          message: '请求失败',
          iconClass: 'fa fa-times'
        })
      })
    },
    skipDetail (id) {
      this.$router.push({path: `/detail/${id}`})
    }
  }
}
</script>

<style lang="less" scoped>
.swiper-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  padding-bottom: 30px;
  .swiper-pagination {
    color: #fff;
    position: fixed;
    bottom: 55px;
  }
  .swiper-scrollbar {
    height: 1px;
    background-color: transparent;
    position: fixed;
    bottom: 55px;
  }
  .swiper-scrollbar-drag {
    background-color: #fff;
  }
  .slider-main {
    width: 90%;
    padding: 0 5%;
    overflow-y: auto;
    padding-bottom: 55px;
    transition: all ease 0.3s;
    &,
    h1,
    h2 {
      color: #fff;
      margin-bottom: 0.5rem;
    }
    .cover {
      padding: 1rem 0;
      img {
        width: 100%;
        // max-height: 10rem;
        // height: 100%;
        border-radius: 8px;

        // border: solid 1px rgba(255, 255, 255, 0.1);
      }
    }
    h2{
      margin-top: 0.5rem;
    }
    .skip {
      text-align: center;
      .mint-button--default.is-plain {
        color: #fff;
        border: 1px solid #fff;
      }
    }
  }
}
</style>
